﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;
using System.Xml;
using System.Xml.Linq;
using System.Windows.Forms;
using System.Text;
namespace XMLMovieWebsite
{
    public partial class MovieList : System.Web.UI.Page
    {
        String getKey_TheLoai, getKey_DanhMuc;

        protected void Page_Load(object sender, EventArgs e)
        {
            getKey_TheLoai = (Request.QueryString["TheLoai"]);
            getKey_DanhMuc = (Request.QueryString["DanhMuc"]);
            loadDulieuRaFileXML();
            layDulieuTuXML();
        }
        
        public void loadDulieuRaFileXML()
        {
            try
            {
                string ConString = ConfigurationManager.ConnectionStrings["ConStringXml"].ConnectionString;
                string CMDString = " SELECT  * FROM movie_thao where  TheLoai like N'%" + getKey_TheLoai + "%' and DanhMuc = N'"+ getKey_DanhMuc+"'";
                SqlConnection con;
                SqlCommand cmd;
                SqlDataAdapter sda;
                DataTable dt;


                using (con = new SqlConnection(ConString))
                {
                    cmd = new SqlCommand(CMDString, con);
                    con.Open();
                    dt = new DataTable("Movie");
                    sda = new SqlDataAdapter(cmd);
                    sda.Fill(dt);
                    if (dt != null)
                    {

                        dt.WriteXml(Server.MapPath("~/App_Data/TheLoai.xml"));
                    }
                    con.Close();

                }
            }
            catch (Exception)
            {

            }


        }
        public void layDulieuTuXML()
        {
            try
            {
                using (DataSet ds = new DataSet())
                {
                    ds.ReadXml(Server.MapPath("~/App_Data/TheLoai.xml"));
                    //GridView1.DataSource = ds;
                    //GridView1.DataBind();
                    DataTable dt = new DataTable();
                    dt = ds.Tables["Movie"];
                    //Image1.ImageUrl =  dt.Rows[0][11].ToString();
                    try
                    {
                    Test.DataSource = dt;
                    Test.DataBind();

                    
                        Paging.PageSize = 4;
                        Paging.DataSource = dt.DefaultView;
                        Paging.BindToControl = Test;
                        Test.DataSource = Paging.DataSourcePaged;
                        lb_theloai.Text = getKey_TheLoai;
                    }
                    catch { }


                }
            }
            catch
            {
                lb_theloai.Text = "Hiện Chưa Có Phim";
            }
        }


    }
}